package dataBase;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;

import com.google.appengine.api.datastore.Email;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.PhoneNumber;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Client {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	@Persistent
	@Unique
	private String userName;
	@Persistent
	private String password;
	@Persistent
	private PhoneNumber phoneNumber;
	@Persistent
	private Email email;
	@Persistent
	private List<Key> allOrdersList = new ArrayList<Key>();
	@Persistent
	private Set<String> ordersTypes = new HashSet<String>();
	@Persistent
	private Date createDate;
	@Persistent
	private Date modifiedDate;
	@Persistent
	private String registId;
	
	public String getRegistId() {
		return registId;
	}

	public void setRegistId(String registId) {
		this.registId = registId;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date create) {
		this.createDate = create;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modified) {
		this.modifiedDate = modified;
	}
	public Key getKey() {
		return key;
	}
	public void setKey(Key key) {
		this.key = key;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public PhoneNumber getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(PhoneNumber phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public Email getEmail() {
		return email;
	}
	public void setEmail(Email email) {
		this.email = email;
	}
	public List<Key> getAllOrdersList() {
		return allOrdersList;
	}
	public void setAllOrdersList(List<Key> allOrdersList) {
		this.allOrdersList = allOrdersList;
	}
	/*public void removeFromAllOrdersList(Order order) {
		this.allOrdersList.remove(order.getKey());
	}*/
	public void clearAllOrdersList() {
		if (allOrdersList!=null)
			allOrdersList.clear();
	}
	public void addToAllOrdersList(Order order) {
		
		if (allOrdersList==null)
			allOrdersList = new ArrayList<Key>();
		
		Key key = order.getKey();
		if (!allOrdersList.contains(key))
			allOrdersList.add(key);
		
	}
	/*public void addToAllOrdersList(Key keyOfOrder) {
		this.allOrdersList.add(keyOfOrder);
	}*/
	
	public Set<String> getOrdersTypes() {
		return ordersTypes;
	}

	public void setOrdersTypes(Set<String> ordersTypes) {
		this.ordersTypes = ordersTypes;
	}
	
	public void addToOrdersType(String type) {
		if(type!=null)
			this.ordersTypes.add(type);
	}

	public void removeOrder(Key key) {
		allOrdersList.remove(key);
		
	}
	

}
